package org.smartstruts.config;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * 该类对应了smart-struts.xml这个配置文件中的action设置
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 */
public class ActionConfig {

	/** 请求路径 */
	private String path;

	/** 对应的Action类型 */
	private String type;

	/** Form类名 */
	private String name;

	/** 方法名,默认值为execute */
	private String method = "execute";

	/** 表单对象存取的地方 */
	private String scope = "session";

	/** 对存取的名字 */
	private String attribute;

	/** 存储了转发对象 */
	private Map<String, ForwardConfig> forwardConfigs = new HashMap<String, ForwardConfig>();

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	/**
	 * 添加一个FrowardConfig对象到本对象的forwardConfigs属性中<br>
	 * 
	 * @param forwardCfg
	 */
	public void addForwardConfig(ForwardConfig forwardCfg) {
		forwardConfigs.put(forwardCfg.getName(), forwardCfg);
	}

	/**
	 * 获得一个forwardConfig对象<br>
	 * 
	 * @param name
	 * @return
	 */
	public ForwardConfig findForward(String name) {
		if (forwardConfigs.containsKey(name)) {
			return forwardConfigs.get(name);
		}
		return null;
	}

	/**
	 * 
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * 
	 * @return
	 */
	public String getScope() {
		return scope;
	}

	/**
	 * 
	 * @param scope
	 */
	public void setScope(String scope) {
		this.scope = scope;
	}

	/**
	 * 
	 * @return
	 */
	public String getAttribute() {
		return attribute;
	}

	/**
	 * 
	 * @param attribute
	 */
	public void setAttribute(String attribute) {
		this.attribute = attribute;
	}

	/**
	 * 
	 * @return
	 */
	public Map<String, ForwardConfig> getForwardConfigs() {
		return forwardConfigs;
	}

	/**
	 * 
	 * @param forwardConfigs
	 */
	public void setForwardConfigs(Map<String, ForwardConfig> forwardConfigs) {
		this.forwardConfigs = forwardConfigs;
	}

	/**
	 * 
	 * @return
	 */
	public String getMethod() {
		return this.method;
	}

	/**
	 * 
	 * @param method
	 */
	public void setMethod(String method) {
		this.method = method;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("path", path).append("type",
				type).toString();
	}

	/**
	 * 
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
		if (attribute == null) {
			this.attribute = name;
		}
	}

}
